import dataC from './data'
import cyMrg from './cyMrg'
import tools from './tools'
export default {
	dhEdge (id, flag) {
	    var edge = dataC.cy.$('#' + id)
	    var edgeD = edge.data()
	    edgeD.visibility = flag
	    edge.style({
	    	visibility: flag
	    	// 'curve-style': edgeD.lineClass
	    })

	},

	dhEdges (id, flag) {
	    dataC.cy.edges(function (i, edge) {
			var data = edge.data()
		      data.visibility = flag
		      if (data.id === id) {
		        try {
		          edge.style({
		            'visibility': data.visibility
		          })
		        } catch (e) {
		          console.log(e)
		        } 
		      }
		})
	},

	clearSelect () {
	    dataC.cy.nodes(function (i, nodes) {
	      //var data = nodes.data()
	      nodes.removeClass('selected')
	    })
    },

	addContainer (id, name) {
		dataC.cy.add({
	      group: 'nodes',
	      // data: { id: id, type: "container", icontype: "bg1",  label: name, color: '#ccc'}
	      data: cyMrg.getContainerNode({
	      	id: id,
	      	label: name,
	      	color: '#ccc',
	      	type: 'container',
	      	linkColor: 'red'
	      })
	    })
		var container = dataC.cy.getElementById(id)
	    return container
	    // return this.findContainer(id)
	},

	findCGroup (id) {
		var nodeTemp = ''
		return dataC.cy.getElementById(id)
	},


	findContainer (id) {
		var nodeTemp = ''
		return dataC.cy.getElementById(id)
	},

	findLine (startId, endId) {
		var line = ''
		var line = dataC.cy.getElementById(id)
		var ed = line.data()

		ed.visibility = "visible"
		line.style({
        	'visibility': ed.visibility
      	})
		
		return line
	},

	findNode (id) {
		return dataC.cy.getElementById(id)
	},

	findIdLine (id) {
		return dataC.cy.getElementById(id)
	},

	dhNode (id, flag) {
		var node = dataC.cy.getElementById(id)
		var data = node.data()
	    data.visibility = flag
	    node.style({
	            'visibility': data.visibility
	          })
		
	},

	getNewEdges () {
		return {
			id: tools.getUUID(),
			label: '',
			color: 'red',
			visibility: 'visible',
			width: 2,
			type: '',
			lineClass: "bezier", 
			lineStyle: 'solid',
			bezier: 0.2,
			source: '',
			target: ''
		}
	},

	getContainerNode (param) {
		return {
			id: param.id || tools.getUUID(),
			label: param.label || '',
			type: 'container',
			icontype: 'bg1',
			linkColor: param.linkColor || 'red',
			level: param.level || '',
			visibility: 'visible',
			color: '#fff'
		}
	},

	getNewNode () {
		return {
			id: tools.getUUID(),
			label: '',
			type: 'tempNode',
			visibility: 'visible',
			color: '#ccc'
		}
	},

	create (id) {
		
	}
}
